package com.example.liang.basamovie.activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.widget.Toast;

import com.example.liang.basamovie.R;
import com.example.liang.basamovie.adapter.FindPlaerInfoAdapter;
import com.example.liang.basamovie.bean.FindPlayerInfoBean;
import com.example.liang.basamovie.json.FindPlayerInfo;
import com.example.liang.basamovie.utils.DataPath;
import com.squareup.okhttp.Request;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

public class PlayerInfoActivity extends AppCompatActivity {

    RecyclerView recyclerView;
    private String newID;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_player_info);
        recyclerView= (RecyclerView) findViewById(R.id.PlayerInfo_RecyclerView);
        initView();
    }

    private void initView() {
        Intent intent = getIntent();
        String id = intent.getStringExtra("url");
        newID = DataPath.FIND_PLAYERINFO_PATH+id;
        Log.e("message", newID);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        //获取数据
        getData();
    }

    private void getData() {
        OkHttpUtils.get().url(newID).build().execute(new StringCallback() {
            @Override
            public void onError(Request request, Exception e) {
                Toast.makeText(PlayerInfoActivity.this,"---作者接口下载失败----",Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onResponse(String response) {
                FindPlayerInfoBean info = FindPlayerInfo.getPlayerInfo(response);
                FindPlaerInfoAdapter adapter = new FindPlaerInfoAdapter(info, PlayerInfoActivity.this);
                recyclerView.setAdapter(adapter);
            }
        });
    }


}
